package com.framework.sec.encoder;


import java.io.UnsupportedEncodingException;

public class SimpleDictCrypt {
	public static String dict = "冬藏閏餘成歲律呂調陽雲騰致雨露結為霜金生麗水玉出崑崗劍號巨闕珠稱夜光果珍李柰菜重芥薑陶唐吊民伐罪周發商湯坐朝問道垂"+ "海鹹河淡鱗潛羽翔龍師火帝鳥官人皇始製文字乃服衣裳推位讓國有虞墨悲絲染詩贊羔羊景行維賢剋念作聖德建名立形端表正空谷傳聲虛堂拱平章愛育黎首臣伏戎羌遐邇壹體率賓歸王"
			+ "鳴鳳在樹白駒食場化被草木賴天地玄黃宇宙洪荒日月盈昃辰宿列張寒來暑往秋收罔談彼短靡恃己長信使可覆器欲難量"
			+ "習聽禍因惡及萬方蓋此身髮四大五常恭惟鞠養豈敢毀傷女慕貞絜男效才良知過必改得能莫忘積福緣善慶尺璧非寶寸陰是競資父事君曰嚴與敬孝當竭力忠則盡命";

	public static String encrypt(String content) throws UnsupportedEncodingException {
		byte[] bytes = content.getBytes("utf-8");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < bytes.length; i++) {
			sb.append(dict.charAt(bytes[i]));
		}
		return sb.reverse().toString();
	}

	public static String decrypt(final String data) throws UnsupportedEncodingException {

		byte[] bytes = new byte[data.length()];
		for (int i = 0; i < bytes.length; i++) {
			bytes[(bytes.length - 1) - i] = (byte) (dict.indexOf(data.charAt(i)));
		}
		return new String(bytes, "utf-8");
	}

	public static void main(String[] args) throws UnsupportedEncodingException {

		String s = SimpleDictCrypt.encrypt("123456");
		System.out.println(s);

		System.out.println(SimpleDictCrypt.decrypt(s));

	}
}

